package com.tgram.android_mapapi.Util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;


public class UtilNum {
	/**
	 * 
	 * @param number
	 * @param length
	 * @return
	 */
	public static String getFormatNum(String number, int length) {
		String num = Integer.toHexString(Integer.parseInt(number));
		return padLeft(num, length);
	}

	private static String padLeft(String str, int length) {
		byte[] bs = new byte[length];
		byte[] ss = str.getBytes();
		Arrays.fill(bs, (byte) (48 & 0xff));
		System.arraycopy(ss, 0, bs, length - ss.length, ss.length);
		return new String(bs);
	}

	/**
	 * 
	 * @param number
	 * @return
	 */
	public static String getBigXString(String number) {
		if (number.contains("x")) {
			number = number.replace("x", "X");
		}
		return number;
	}

	/**
	 * 
	 * @param xml
	 * @return
	 */
	public static String getUTF8XMLString(String string) {
		// A StringBuffer Object
		StringBuffer sb = new StringBuffer();
		sb.append(string);
		String strString = "";
		String strUTF8 = "";
		try {
			strString = new String(sb.toString().getBytes("UTF-8"));
			strUTF8 = URLEncoder.encode(strString, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return strUTF8;
	}
}
